import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/17 14:32
 * @description 计数数组
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] di = {13,37,58}, pro = {4, 90, 96}, wor = { 34,73,45};
        System.out.println(1e5);
        solution.maxProfitAssignment(di, pro, wor);
    }
    public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {
        int[] map = new int[(int) (1e5 + 1)];
        // 使得每个难度对应的收益是最大的 (不排除难度小反而收益高)
        int maxD = 0;
        for(int i = 0; i < difficulty.length; ++i) {
            if(profit[i] > map[difficulty[i]]) {
                map[difficulty[i]] = profit[i];
            }
            if(difficulty[i] > maxD) {
                maxD = difficulty[i];
            }
        }
        for(int i = 1; i <= maxD; i++) {
            if(map[i - 1] > map[i]) {
                // 难度小的利润更高，那么i难度的最大利润为map[i-1]
                map[i] = map[i - 1];
            }
        }
        int res = 0;
        for(int d : worker) {
            res += d > maxD ? map[maxD] : map[d];
        }
        return res;
    }
}
